//
//  ViewController.m
//  DataBindExample
//
//  Created by Super on 2019/12/20.
//  Copyright © 2019 Super. All rights reserved.
//

#import "ViewController.h"
#import "DataBindManage.h"
#import "TestModel.h"

#import "SecondViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *firstLabel;
@property (weak, nonatomic) IBOutlet UILabel *secondLabel;

@property (nonatomic, strong) TestModel *model;

@property (nonatomic, assign) NSInteger colorTag;
@property (nonatomic, assign) NSInteger num;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.model = [TestModel new];
    self.model.num = 985;
    self.colorTag = 1;
    
    [self bindModel:self.model modelKey:@"num" viewInfo:self.firstLabel.textInfo block:^{
        NSLog(@"数据更新啦1");
    }];
    
    [self bindModel:self.model modelKey:@"color" viewInfo:self.firstLabel.textColorInfo block:^{
        NSLog(@"数据更新啦2");
    }];
    
    [self bindPropertyWithKey:@"num" viewInfo:self.secondLabel.textInfo block:^{
        NSLog(@"数据更新啦3");
    }];
    
}

- (IBAction)pushVC:(id)sender {
    SecondViewController *vc = [SecondViewController new];
    vc.model = self.model;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)addNumBindModel:(id)sender {
    self.model.num++;
}

- (IBAction)minusNumBindModel:(id)sender {
    self.model.num--;
}

- (IBAction)changeColorBindModel:(id)sender {
    self.colorTag = self.colorTag * -1;
    if (self.colorTag > 0) {
        self.model.color = [UIColor redColor];
    } else {
        self.model.color = [UIColor blueColor];
    }
}

- (IBAction)updateViewDataBindModel:(id)sender {
    self.firstLabel.text = @"404";
}

- (IBAction)addNumBindProp:(id)sender {
    self.num++;
}

- (IBAction)minusNumBindProp:(id)sender {
    self.num--;
}

- (IBAction)updateViewDataBindProp:(id)sender {
    self.secondLabel.text = @"251";
}

@end
